import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:memo_rcl/views/register_page.dart';

class LoginActivity extends StatefulWidget {
  static const String id = "LoginActivity";

  const LoginActivity({super.key});

  @override
  State<LoginActivity> createState() => _LoginActivityState();
}

class _LoginActivityState extends State<LoginActivity> {
  @override
  Widget build(BuildContext context) {
    //设置系统 UI 覆盖层（状态栏）
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.transparent, // 状态栏背景透明
        statusBarIconBrightness: Brightness.light, // Android 状态栏图标亮色
        statusBarBrightness: Brightness.dark, // iOS 状态栏样式深色
      ),
      child: Scaffold(
        backgroundColor: Colors.white,
        body: SingleChildScrollView(
          child: Column(
            children: [
              Image.asset("assets/images/denglu_logo_img.png"),
              SizedBox(height: 5),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 30),
                width: double.infinity,
                height: 50,
                child: Row(
                  spacing: 15,
                  children: [
                    Image.asset(
                      "assets/images/shoujihao_icon.png",
                      width: 15,
                      height: 15,
                    ),
                    Expanded(
                      child: TextField(
                        decoration: InputDecoration(
                          hintText: "账号",
                          hintStyle: TextStyle(
                            color: Color(0xffb6b6b6),
                            fontSize: 16,
                          ),
                          /*设置默认的输入框下边线颜色*/
                          enabledBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Color(0xffdedede)),
                          ),
                          focusedBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Color(0xffdedede)),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(height: 20),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 30),
                width: double.infinity,
                height: 50,
                child: Column(
                  children: [
                    Row(
                      spacing: 15,
                      children: [
                        Image.asset(
                          "assets/images/mima_icon.png",
                          width: 15,
                          height: 15,
                        ),
                        Expanded(
                          child: TextField(
                            decoration: InputDecoration(
                              hintText: "请输入密码",
                              hintStyle: TextStyle(
                                color: Color(0xffb6b6b6),
                                fontSize: 16,
                              ),
                              border: InputBorder.none, // 去掉默认下划线
                            ),
                          ),
                        ),
                        Container(
                          width: 1,
                          height: 20,
                          color: Color(0xffe0e0e0),
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 10),
                          child: Text(
                            "忘记密码？",
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xff0784dc),
                            ),
                          ),
                        ),
                      ],
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 30),
                      height: 1,
                      width: double.infinity,
                      color: Color(0xffdedede),
                    ),
                  ],
                ),
              ),
              SizedBox(height: 35),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 60),
                height: 65,
                width: double.infinity,
                child: ElevatedButton(
                  style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(
                      Color(0xff0784dc),
                    ),
                  ),
                  onPressed: () {},
                  child: Text(
                    "登录",
                    style: TextStyle(fontSize: 20, color: Colors.white),
                  ),
                ),
              ),
              SizedBox(height: 20),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 40),
                width: double.infinity,
                child: GestureDetector(
                  child: Center(child: ClickText(text: "注册账号")),
                  onTap: () {
                    Navigator.pushNamed(context, RegisterPage.id);
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class ToggleButton extends StatelessWidget {
  const ToggleButton({
    required this.textLabel,
    required this.selected,
    this.onTap,
  });

  final bool selected;
  final String textLabel;
  final GestureTapCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: GestureDetector(
        onTap: onTap,
        child: Container(
          height: double.infinity,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(22),
            color: Color(selected ? 0xff0784dc : 0xfff6f6f6),
          ),
          alignment: Alignment.center,
          child: Text(
            textLabel,
            style: TextStyle(
              fontSize: 16,
              color: selected ? Colors.white : Colors.black,
            ),
          ),
        ),
      ),
    );
  }
}

class ClickText extends StatelessWidget {
  const ClickText({required this.text});

  final String text;

  @override
  Widget build(BuildContext context) {
    return Text(
      text,
      style: TextStyle(
        fontSize: 18,
        color: Color(0xff0784dc),
        decoration: TextDecoration.underline,
        decorationColor: Color(0xff0784dc),
      ),
    );
  }
}
